## Total Prophet ----------------------------------------------------------------# total_forecast2 <- total_baseline_forecast %>% # filter(ds >= as.POSIXct("2022-08-07"))# # performance_total <- full_join(total_test, total_forecast2, by = join_by(ds == ds)) %>% # select(ds, y, yhat)# # # Check MAE value# total_baseline_mae <- mae(performance_total$y, performance_total$yhat)# print(paste("The MAE for the total model is", total_baseline_mae))# # # Check MASE value# total_baseline_mase <- mase(performance_total$y, performance_total$yhat)# print(paste("The MASE for the total model is", total_baseline_mase))
East
Code
## east Prophet ----------------------------------------------------------------east_forecast2 <- east_baseline_forecast %>%filter(ds >=as.POSIXct("2022-11-29"))performance_east <-full_join(east_test, east_forecast2, by =join_by(ds == ds)) %>%select(ds, y, yhat) %>%mutate(yhat =case_when((yhat <0) ~0,.default = yhat))performance_east %>%ggplot() +geom_line(aes(x = ds, y = y, color ="dodgerblue"), linewidth =1) +geom_line(aes(x = ds, y = yhat, color ="orange"), linewidth =1) +scale_color_manual(values =c("dodgerblue", "orange"), labels =c("Actual", "Predicted")) +theme_bw() +theme(legend.title =element_blank())
Code
# Check MAE valueeast_baseline_prophet_mae <-mae(performance_east$y, performance_east$yhat)print(paste("The MAE for the East model is", east_baseline_prophet_mae))
[1] "The MAE for the East model is 237.089514471189"
Code
# Check MASE valueeast_baseline_prophet_mase <-mase(performance_east$y, performance_east$yhat)print(paste("The MASE for the East model is", east_baseline_prophet_mase))
[1] "The MASE for the East model is 2.67696993757437"
Midwest
Code
## Midwest Prophet ----------------------------------------------------------------midwest_forecast2 <- midwest_baseline_forecast %>%filter(ds >=as.POSIXct("2022-11-29"))performance_midwest <-full_join(midwest_test, midwest_forecast2, by =join_by(ds == ds)) %>%select(ds, y, yhat) %>%mutate(yhat =case_when((yhat <0) ~0,.default = yhat))performance_midwest %>%ggplot() +geom_line(aes(x = ds, y = y, color ="dodgerblue"), linewidth =1) +geom_line(aes(x = ds, y = yhat, color ="orange"), linewidth =1) +scale_color_manual(values =c("dodgerblue", "orange"), labels =c("Actual", "Predicted")) +theme_bw() +theme(legend.title =element_blank())
Code
# Check MAE valuemidwest_baseline_prophet_mae<-mae(performance_midwest$y, performance_midwest$yhat)print(paste("The MAE for the Midwest model is", midwest_baseline_prophet_mae))
[1] "The MAE for the Midwest model is 206.704062553125"
Code
# Check MASE valuemidwest_baseline_prophet_mase <-mase(performance_midwest$y, performance_midwest$yhat)print(paste("The MASE for the Midwest model is", midwest_baseline_prophet_mase))
[1] "The MASE for the Midwest model is 1.78629237293538"
South
Code
## South Prophet ----------------------------------------------------------------south_forecast2 <- south_baseline_forecast %>%filter(ds >=as.POSIXct("2022-11-29"))performance_south <-full_join(south_test, south_forecast2, by =join_by(ds == ds)) %>%select(ds, y, yhat) %>%mutate(yhat =case_when((yhat <0) ~0,.default = yhat))performance_south %>%ggplot() +geom_line(aes(x = ds, y = y, color ="dodgerblue"), linewidth =1) +geom_line(aes(x = ds, y = yhat, color ="orange"), linewidth =1) +scale_color_manual(values =c("dodgerblue", "orange"), labels =c("Actual", "Predicted")) +theme_bw() +theme(legend.title =element_blank())
Code
# Check MAE valuesouth_baseline_prophet_mae<-mae(performance_south$y, performance_south$yhat)print(paste("The MAE for the South model is", south_baseline_prophet_mae))
[1] "The MAE for the South model is 187.484789291692"
Code
# Check MASE valuesouth_baseline_prophet_mase <-mase(performance_south$y, performance_south$yhat)print(paste("The MASE for the South model is", south_baseline_prophet_mase))
[1] "The MASE for the South model is 0.969911696651615"
West
Code
## West Prophet ----------------------------------------------------------------west_forecast2 <- west_baseline_forecast %>%filter(ds >=as.POSIXct("2022-11-29"))performance_west <-full_join(west_test, west_forecast2, by =join_by(ds == ds)) %>%select(ds, y, yhat) %>%mutate(yhat =case_when((yhat <0) ~0,.default = yhat))performance_west %>%ggplot() +geom_line(aes(x = ds, y = y, color ="dodgerblue"), linewidth =1) +geom_line(aes(x = ds, y = yhat, color ="orange"), linewidth =1) +scale_color_manual(values =c("dodgerblue", "orange"), labels =c("Actual", "Predicted")) +theme_bw() +theme(legend.title =element_blank())
Code
# Check MAE valuewest_baseline_prophet_mae<-mae(performance_west$y, performance_west$yhat)print(paste("The MAE for the West model is", west_baseline_prophet_mae))
[1] "The MAE for the West model is 188.578880006121"
Code
# Check MASE valuewest_baseline_prophet_mase <-mase(performance_west$y, performance_west$yhat)print(paste("The MASE for the West model is", west_baseline_prophet_mase))
[1] "The MASE for the West model is 2.1079645306847"
# Create prophet model with CI of 95%# total_changepoint <- prophet(total_train, interval.width = 0.95, n.changepoints = 2)east_changepoint <-prophet(east_train, interval.width =0.95, n.changepoints =9)midwest_changepoint <-prophet(midwest_train, interval.width =0.95, n.changepoints =1)south_changepoint <-prophet(south_train, interval.width =0.95, n.changepoints =5)west_changepoint <-prophet(west_train, interval.width =0.95, n.changepoints =2)
4.2 New Changepoints Model Forecast
Total
Code
# Create time range for forecast# total_changepoint_future <- make_future_dataframe(total_changepoint, freq = "day", periods = nrow(total_test))# # # Make prediction# total_changepoint_forecast <- predict(total_changepoint, total_changepoint_future )# # # Visualize the forecast# plot(total_changepoint, total_changepoint_forecast ) +# labs(title = "Total Changepoint Prophet Model")
East
Code
# Create time range for forecasteast_changepoint_future <-make_future_dataframe(east_changepoint, freq ="day", periods =nrow(east_test))# Make predictioneast_changepoint_forecast <-predict(east_changepoint, east_changepoint_future )# Visualize the forecastplot(east_changepoint, east_changepoint_forecast ) +labs(title ="East Changepoint Prophet Model")
Midwest
Code
# Create time range for forecastmidwest_changepoint_future <-make_future_dataframe(midwest_changepoint, freq ="day", periods =nrow(midwest_test))# Make predictionmidwest_changepoint_forecast <-predict(midwest_changepoint, midwest_changepoint_future )# Visualize the forecastplot(midwest_changepoint, midwest_changepoint_forecast ) +labs(title ="Midwest Changepoint Prophet Model")
South
Code
# Create time range for forecastsouth_changepoint_future <-make_future_dataframe(south_changepoint, freq ="day", periods =nrow(south_test))# Make predictionsouth_changepoint_forecast <-predict(south_changepoint, south_changepoint_future )# Visualize the forecastplot(south_changepoint, south_changepoint_forecast ) +labs(title ="South Changepoint Prophet Model")
West
Code
# Create time range for forecastwest_changepoint_future <-make_future_dataframe(west_changepoint, freq ="day", periods =nrow(west_test))# Make predictionwest_changepoint_forecast <-predict(west_changepoint, west_changepoint_future )# Visualize the forecastplot(west_changepoint, west_changepoint_forecast ) +labs(title ="West Changepoint Prophet Model")
4.3 Changepoint Accuracy
Code
## Total Prophet ----------------------------------------------------------------# total_forecast2 <- total_changepoint_forecast %>% # filter(ds >= as.POSIXct("2022-08-07"))# # performance_total <- full_join(total_test, total_forecast2, by = join_by(ds == ds)) %>% # select(ds, y, yhat)# # # Check MAE value# total_changepoint_mae <- mae(performance_total$y, performance_total$yhat)# print(paste("The MAE for the total changepoint model is", total_changepoint_mae))# # # Check MASE value# total_changepoint_mase <- mase(performance_total$y, performance_total$yhat)# print(paste("The MASE for the total changepoint model is", total_changepoint_mase))
Code
## east Prophet ----------------------------------------------------------------east_forecast2 <- east_changepoint_forecast %>%filter(ds >as.POSIXct("2022-11-29"))performance_east <-full_join(east_test, east_forecast2, by =join_by(ds == ds)) %>%select(ds, y, yhat) %>%mutate(yhat =case_when((yhat <0) ~0,.default = yhat))performance_east %>%ggplot() +geom_line(aes(x = ds, y = y, color ="dodgerblue"), linewidth =1) +geom_line(aes(x = ds, y = yhat, color ="orange"), linewidth =1) +scale_color_manual(values =c("dodgerblue", "orange"), labels =c("Actual", "Predicted")) +theme_bw() +theme(legend.title =element_blank())
Code
# Check MAE valueeast_changepoint_mae <-mae(performance_east$y, performance_east$yhat)print(paste("The MAE for the east changepoint model is", east_changepoint_mae))
[1] "The MAE for the east changepoint model is 233.164762809544"
Code
# Check MASE valueeast_changepoint_mase <-mase(performance_east$y, performance_east$yhat)print(paste("The MASE for the east changepoint model is", east_changepoint_mase))
[1] "The MASE for the east changepoint model is 2.6326556951917"
Code
## midwest Prophet ----------------------------------------------------------------midwest_forecast2 <- midwest_changepoint_forecast %>%filter(ds >as.POSIXct("2022-11-29"))performance_midwest <-full_join(midwest_test, midwest_forecast2, by =join_by(ds == ds)) %>%select(ds, y, yhat) %>%mutate(yhat =case_when((yhat <0) ~0,.default = yhat))performance_midwest %>%ggplot() +geom_line(aes(x = ds, y = y, color ="dodgerblue"), linewidth =1) +geom_line(aes(x = ds, y = yhat, color ="orange"), linewidth =1) +scale_color_manual(values =c("dodgerblue", "orange"), labels =c("Actual", "Predicted")) +theme_bw() +theme(legend.title =element_blank())
Code
# Check MAE valuemidwest_changepoint_mae <-mae(performance_midwest$y, performance_midwest$yhat)print(paste("The MAE for the midwest changepoint model is", midwest_changepoint_mae))
[1] "The MAE for the midwest changepoint model is 196.101957509046"
Code
# Check MASE valuemidwest_changepoint_mase <-mase(performance_midwest$y, performance_midwest$yhat)print(paste("The MASE for the midwest changepoint model is", midwest_changepoint_mase))
[1] "The MASE for the midwest changepoint model is 1.69467124491605"
Code
## south Prophet ----------------------------------------------------------------south_forecast2 <- south_changepoint_forecast %>%filter(ds >as.POSIXct("2022-11-29"))performance_south <-full_join(south_test, south_forecast2, by =join_by(ds == ds)) %>%select(ds, y, yhat) %>%mutate(yhat =case_when((yhat <0) ~0,.default = yhat))performance_south %>%ggplot() +geom_line(aes(x = ds, y = y, color ="dodgerblue"), linewidth =1) +geom_line(aes(x = ds, y = yhat, color ="orange"), linewidth =1) +scale_color_manual(values =c("dodgerblue", "orange"), labels =c("Actual", "Predicted")) +theme_bw() +theme(legend.title =element_blank())
Code
# Check MAE valuesouth_changepoint_mae <-mae(performance_south$y, performance_south$yhat)print(paste("The MAE for the south changepoint model is", south_changepoint_mae))
[1] "The MAE for the south changepoint model is 180.392424483349"
Code
# Check MASE valuesouth_changepoint_mase <-mase(performance_south$y, performance_south$yhat)print(paste("The MASE for the south changepoint model is", south_changepoint_mase))
[1] "The MASE for the south changepoint model is 0.933220893037517"
Code
## west Prophet ----------------------------------------------------------------west_changepoint <-prophet(west_train, interval.width =0.95, n.changepoints =1)west_changepoint_future <-make_future_dataframe(west_changepoint, freq ="day", periods =nrow(west_test))# Make predictionwest_changepoint_forecast <-predict(west_changepoint, west_changepoint_future )west_forecast2 <- west_changepoint_forecast %>%filter(ds >as.POSIXct("2022-11-29"))performance_west <-full_join(west_test, west_forecast2, by =join_by(ds == ds)) %>%select(ds, y, yhat) %>%mutate(yhat =case_when((yhat <0) ~0,.default = yhat))performance_west %>%ggplot() +geom_line(aes(x = ds, y = y, color ="dodgerblue"), linewidth =1) +geom_line(aes(x = ds, y = yhat, color ="orange"), linewidth =1) +scale_color_manual(values =c("dodgerblue", "orange"), labels =c("Actual", "Predicted")) +theme_bw() +theme(legend.title =element_blank())
Code
# Check MAE valuewest_changepoint_mae <-mae(performance_west$y, performance_west$yhat)print(paste("The MAE for the west changepoint model is", west_changepoint_mae))
[1] "The MAE for the west changepoint model is 153.213158938851"
Code
# Check MASE valuewest_changepoint_mase <-mase(performance_west$y, performance_west$yhat)print(paste("The MASE for the west changepoint model is", west_changepoint_mase))
[1] "The MASE for the west changepoint model is 1.71264091008904"
5. Seasonality Models
5.1 Build Models with Seasonality
Code
## Total -----------------------------------------------------------------------# ### Initialize & Fit the Prophet ----# total_season_prophet <- prophet(total_train, yearly.seasonality = FALSE, weekly.seasonality = FALSE)# # ### Forecast Future Predictions ----# total_season_future <- make_future_dataframe(total_season_prophet, periods = nrow(total_test), freq = "day")# total_season_forecast <- predict(total_season_prophet, total_season_future)## East Region -----------------------------------------------------------------### Initialize & Fit the Prophet ----east_season_prophet <-prophet(east_train, yearly.seasonality =FALSE, weekly.seasonality =TRUE)### Forecast Future Predictions ----east_season_future <-make_future_dataframe(east_season_prophet, periods =nrow(east_test), freq ="day")east_season_forecast <-predict(east_season_prophet, east_season_future)### Initialize & Fit the Prophet ----midwest_season_prophet <-prophet(midwest_train, yearly.seasonality =FALSE, weekly.seasonality =TRUE)### Forecast Future Predictions ----midwest_season_future <-make_future_dataframe(midwest_season_prophet, periods =nrow(midwest_test), freq ="day")midwest_season_forecast <-predict(midwest_season_prophet, midwest_season_future)## South Region -----------------------------------------------------------------### Initialize & Fit the Prophet ----south_season_prophet <-prophet(south_train, yearly.seasonality =FALSE, weekly.seasonality =TRUE)### Forecast Future Predictions ----south_season_future <-make_future_dataframe(south_season_prophet, periods =nrow(south_test), freq ="day")south_season_forecast <-predict(south_season_prophet, south_season_future)## West Region -----------------------------------------------------------------### Initialize & Fit the Prophet ----west_season_prophet <-prophet(west_train, yearly.seasonality =FALSE, weekly.seasonality =TRUE)### Forecast Future Predictions ----west_season_future <-make_future_dataframe(west_season_prophet, periods =nrow(west_test), freq ="day")west_season_forecast <-predict(west_season_prophet, west_season_future)
5.2 Plotting Forecasts
Code
# plot(total_season_prophet, total_season_forecast) +# geom_point(data = total_test, aes(x = as.POSIXct.Date(ds), y = y), alpha = 0.2) +# theme_minimal() +# labs(title = "Total Season Univariate Prophet",# x = "Date",# y = "Daily Deaths")# # prophet_plot_components(total_season_prophet, total_season_forecast) east_season_prophet_plot <-plot(east_season_prophet, east_season_forecast) +theme_minimal() +labs(title ="East season Univariate Prophet",x ="Date",y ="Daily Deaths")east_season_prophet_plot
## Total Prophet ----------------------------------------------------------------# total_forecast2 <- total_season_forecast %>% # filter(ds >= as.POSIXct("2022-08-07"))# # performance_total <- full_join(total_test, total_forecast2, by = join_by(ds == ds)) %>% # select(ds, y, yhat)# # # Check MAE value# total_season_mae <- mae(performance_total$y, performance_total$yhat)# print(paste("The MAE for the total model is", total_season_mae))# # # Check MASE value# total_season_mase <- mase(performance_total$y, performance_total$yhat)# print(paste("The MASE for the total model is", total_season_mase))
East
Code
## east Prophet ----------------------------------------------------------------east_forecast2 <- east_season_forecast %>%filter(ds >=as.POSIXct("2022-11-29"))performance_east <-full_join(east_test, east_forecast2, by =join_by(ds == ds)) %>%select(ds, y, yhat) %>%mutate(yhat =case_when((yhat <0) ~0,.default = yhat))season_east_plot <- performance_east %>%ggplot() +geom_line(aes(x = ds, y = y, color ="dodgerblue"), linewidth =1) +geom_line(aes(x = ds, y = yhat, color ="orange"), linewidth =1) +scale_color_manual(values =c("dodgerblue", "orange"), labels =c("Actual", "Predicted")) +theme_bw() +theme(legend.title =element_blank()) season_east_plot
Code
# Check MAE valueeast_season_prophet_mae <-mae(performance_east$y, performance_east$yhat)print(paste("The MAE for the East model is", east_season_prophet_mae))
[1] "The MAE for the East model is 54.5672305553463"
Code
# Check MASE valueeast_season_prophet_mase <-mase(performance_east$y, performance_east$yhat)print(paste("The MASE for the East model is", east_season_prophet_mase))
[1] "The MASE for the East model is 0.616116811825952"
Midwest
Code
## Midwest Prophet ----------------------------------------------------------------midwest_forecast2 <- midwest_season_forecast %>%filter(ds >=as.POSIXct("2022-11-29"))performance_midwest <-full_join(midwest_test, midwest_forecast2, by =join_by(ds == ds)) %>%select(ds, y, yhat) %>%mutate(yhat =case_when((yhat <0) ~0,.default = yhat))performance_midwest %>%ggplot() +geom_line(aes(x = ds, y = y, color ="dodgerblue"), linewidth =1) +geom_line(aes(x = ds, y = yhat, color ="orange"), linewidth =1) +scale_color_manual(values =c("dodgerblue", "orange"), labels =c("Actual", "Predicted")) +theme_bw() +theme(legend.title =element_blank())
Code
# Check MAE valuemidwest_season_prophet_mae<-mae(performance_midwest$y, performance_midwest$yhat)print(paste("The MAE for the Midwest model is", midwest_season_prophet_mae))
[1] "The MAE for the Midwest model is 78.012979316311"
Code
# Check MASE valuemidwest_season_prophet_mase <-mase(performance_midwest$y, performance_midwest$yhat)print(paste("The MASE for the Midwest model is", midwest_season_prophet_mase))
[1] "The MASE for the Midwest model is 0.674171509845759"
South
Code
## South Prophet ----------------------------------------------------------------south_forecast2 <- south_season_forecast %>%filter(ds >=as.POSIXct("2022-11-29"))performance_south <-full_join(south_test, south_forecast2, by =join_by(ds == ds)) %>%select(ds, y, yhat) %>%mutate(yhat =case_when((yhat <0) ~0,.default = yhat))performance_south %>%ggplot() +geom_line(aes(x = ds, y = y, color ="dodgerblue"), linewidth =1) +geom_line(aes(x = ds, y = yhat, color ="orange"), linewidth =1) +scale_color_manual(values =c("dodgerblue", "orange"), labels =c("Actual", "Predicted")) +theme_bw() +theme(legend.title =element_blank())
Code
# Check MAE valuesouth_season_prophet_mae<-mae(performance_south$y, performance_south$yhat)print(paste("The MAE for the South model is", south_season_prophet_mae))
[1] "The MAE for the South model is 116.790330893076"
Code
# Check MASE valuesouth_season_prophet_mase <-mase(performance_south$y, performance_south$yhat)print(paste("The MASE for the South model is", south_season_prophet_mase))
[1] "The MASE for the South model is 0.604189323395027"
West
Code
## West Prophet ----------------------------------------------------------------west_forecast2 <- west_season_forecast %>%filter(ds >=as.POSIXct("2022-11-29"))performance_west <-full_join(west_test, west_forecast2, by =join_by(ds == ds)) %>%select(ds, y, yhat) %>%mutate(yhat =case_when((yhat <0) ~0,.default = yhat))performance_west %>%ggplot() +geom_line(aes(x = ds, y = y, color ="dodgerblue"), linewidth =1) +geom_line(aes(x = ds, y = yhat, color ="orange"), linewidth =1) +scale_color_manual(values =c("dodgerblue", "orange"), labels =c("Actual", "Predicted")) +theme_bw() +theme(legend.title =element_blank())
Code
# Check MAE valuewest_season_prophet_mae<-mae(performance_west$y, performance_west$yhat)print(paste("The MAE for the West model is", west_season_prophet_mae))
[1] "The MAE for the West model is 68.7293340234711"
Code
# Check MASE valuewest_season_prophet_mase <-mase(performance_west$y, performance_west$yhat)print(paste("The MASE for the West model is", west_season_prophet_mase))
[1] "The MASE for the West model is 0.768267360238622"
# total_holiday <- prophet(total_train, holidays = events, fit = FALSE)# # # Add built-in country-specific holidays# total_holiday <- add_country_holidays(total_holiday, country_name = 'US')# # # Fit model on training# total_holiday_prophet <- fit.prophet(total_holiday, total_train)
Code
east_holiday <-prophet(east_train, holidays = events, fit =FALSE)# Add built-in country-specific holidayseast_holiday <-add_country_holidays(east_holiday, country_name ='US')# Fit model on trainingeast_holiday_prophet <-fit.prophet(east_holiday, east_train)
Code
midwest_holiday <-prophet(midwest_train, holidays = events, fit =FALSE)# Add built-in country-specific holidaysmidwest_holiday <-add_country_holidays(midwest_holiday, country_name ='US')# Fit model on trainingmidwest_holiday_prophet <-fit.prophet(midwest_holiday, midwest_train)
Code
south_holiday <-prophet(south_train, holidays = events, fit =FALSE)# Add built-in country-specific holidayssouth_holiday <-add_country_holidays(south_holiday, country_name ='US')# Fit model on trainingsouth_holiday_prophet <-fit.prophet(south_holiday, south_train)
Code
west_holiday <-prophet(west_train, holidays = events, fit =FALSE)# Add built-in country-specific holidayswest_holiday <-add_country_holidays(west_holiday, country_name ='US')# Fit model on trainingwest_holiday_prophet <-fit.prophet(west_holiday, west_train)
6.2 Holiday Model Forecast
Code
### Forecast Future Predictions ----# total_holiday_future <- make_future_dataframe(total_holiday_prophet, periods = nrow(total_test), freq = "day")# total_holiday_forecast <- predict(total_holiday_prophet, total_holiday_future)### East ----east_holiday_future <-make_future_dataframe(east_holiday_prophet, periods =nrow(east_test), freq ="day")east_holiday_forecast <-predict(east_holiday_prophet, east_holiday_future)### Midwest ----midwest_holiday_future <-make_future_dataframe(midwest_holiday_prophet, periods =nrow(midwest_test), freq ="day")midwest_holiday_forecast <-predict(midwest_holiday_prophet, midwest_holiday_future)### South ----south_holiday_future <-make_future_dataframe(south_holiday_prophet, periods =nrow(south_test), freq ="day")south_holiday_forecast <-predict(south_holiday_prophet, south_holiday_future)### West ----west_holiday_future <-make_future_dataframe(west_holiday_prophet, periods =nrow(west_test), freq ="day")west_holiday_forecast <-predict(west_holiday_prophet, west_holiday_future)
# ## Total Prophet ----------------------------------------------------------------# total_forecast2 <- total_holiday_forecast %>% # filter(ds >= as.POSIXct("2022-08-07"))# # performance_total <- full_join(total_test, total_forecast2, by = join_by(ds == ds)) %>% # select(ds, y, yhat)# # # Check MAE value# total_holiday_mae <- mae(performance_total$y, performance_total$yhat)# print(paste("The MAE for the total model is", total_holiday_mae))# # # Check MASE value# total_holiday_mase <- mase(performance_total$y, performance_total$yhat)# print(paste("The MASE for the total model is", total_holiday_mase))
East
Code
## east Prophet ----------------------------------------------------------------east_forecast2 <- east_holiday_forecast %>%filter(ds >=as.POSIXct("2022-11-29"))performance_east <-full_join(east_test, east_forecast2, by =join_by(ds == ds)) %>%select(ds, y, yhat) %>%mutate(yhat =case_when((yhat <0) ~0,.default = yhat))performance_east %>%ggplot() +geom_line(aes(x = ds, y = y, color ="dodgerblue"), linewidth =1) +geom_line(aes(x = ds, y = yhat, color ="orange"), linewidth =1) +scale_color_manual(values =c("dodgerblue", "orange"), labels =c("Actual", "Predicted")) +theme_bw() +theme(legend.title =element_blank())
Code
# Check MAE valueeast_holiday_prophet_mae <-mae(performance_east$y, performance_east$yhat)print(paste("The MAE for the East model is", east_holiday_prophet_mae))
[1] "The MAE for the East model is 238.789924240928"
Code
# Check MASE valueeast_holiday_prophet_mase <-mase(performance_east$y, performance_east$yhat)print(paste("The MASE for the East model is", east_holiday_prophet_mase))
[1] "The MASE for the East model is 2.69616920855564"
Midwest
Code
## Midwest Prophet ----------------------------------------------------------------midwest_forecast2 <- midwest_holiday_forecast %>%filter(ds >=as.POSIXct("2022-11-29"))performance_midwest <-full_join(midwest_test, midwest_forecast2, by =join_by(ds == ds)) %>%select(ds, y, yhat) %>%mutate(yhat =case_when((yhat <0) ~0,.default = yhat))performance_midwest %>%ggplot() +geom_line(aes(x = ds, y = y, color ="dodgerblue"), linewidth =1) +geom_line(aes(x = ds, y = yhat, color ="orange"), linewidth =1) +scale_color_manual(values =c("dodgerblue", "orange"), labels =c("Actual", "Predicted")) +theme_bw() +theme(legend.title =element_blank())
Code
# Check MAE valuemidwest_holiday_prophet_mae<-mae(performance_midwest$y, performance_midwest$yhat)print(paste("The MAE for the Midwest model is", midwest_holiday_prophet_mae))
[1] "The MAE for the Midwest model is 206.24646986654"
Code
# Check MASE valuemidwest_holiday_prophet_mase <-mase(performance_midwest$y, performance_midwest$yhat)print(paste("The MASE for the Midwest model is", midwest_holiday_prophet_mase))
[1] "The MASE for the Midwest model is 1.78233795464355"
South
Code
## South Prophet ----------------------------------------------------------------south_forecast2 <- south_holiday_forecast %>%filter(ds >=as.POSIXct("2022-11-29"))performance_south <-full_join(south_test, south_forecast2, by =join_by(ds == ds)) %>%select(ds, y, yhat) %>%mutate(yhat =case_when((yhat <0) ~0,.default = yhat))performance_south %>%ggplot() +geom_line(aes(x = ds, y = y, color ="dodgerblue"), linewidth =1) +geom_line(aes(x = ds, y = yhat, color ="orange"), linewidth =1) +scale_color_manual(values =c("dodgerblue", "orange"), labels =c("Actual", "Predicted")) +theme_bw() +theme(legend.title =element_blank())
Code
# Check MAE valuesouth_holiday_prophet_mae<-mae(performance_south$y, performance_south$yhat)print(paste("The MAE for the South model is", south_holiday_prophet_mae))
[1] "The MAE for the South model is 163.323431945501"
Code
# Check MASE valuesouth_holiday_prophet_mase <-mase(performance_south$y, performance_south$yhat)print(paste("The MASE for the South model is", south_holiday_prophet_mase))
[1] "The MASE for the South model is 0.844918180187776"
West
Code
## West Prophet ----------------------------------------------------------------west_forecast2 <- west_holiday_forecast %>%filter(ds >=as.POSIXct("2022-11-29"))performance_west <-full_join(west_test, west_forecast2, by =join_by(ds == ds)) %>%select(ds, y, yhat) %>%mutate(yhat =case_when((yhat <0) ~0,.default = yhat))performance_west %>%ggplot() +geom_line(aes(x = ds, y = y, color ="dodgerblue"), linewidth =1) +geom_line(aes(x = ds, y = yhat, color ="orange"), linewidth =1) +scale_color_manual(values =c("dodgerblue", "orange"), labels =c("Actual", "Predicted")) +theme_bw() +theme(legend.title =element_blank())
Code
# Check MAE valuewest_holiday_prophet_mae<-mae(performance_west$y, performance_west$yhat)print(paste("The MAE for the West model is", west_holiday_prophet_mae))
[1] "The MAE for the West model is 175.645173914968"
Code
# Check MASE valuewest_holiday_prophet_mase <-mase(performance_west$y, performance_west$yhat)print(paste("The MASE for the West model is", west_holiday_prophet_mase))
[1] "The MASE for the West model is 1.96338951947685"
## Total Prophet ----------------------------------------------------------------# total_forecast2 <- total_best_forecast %>% # filter(ds >= as.POSIXct("2022-08-07"))# # performance_total <- full_join(total_test, total_forecast2, by = join_by(ds == ds)) %>% # select(ds, y, yhat)# # # Check MAE value# total_best_mae <- mae(performance_total$y, performance_total$yhat)# print(paste("The MAE for the total model is", total_best_mae))# # # Check MASE value# total_best_mase <- mase(performance_total$y, performance_total$yhat)# print(paste("The MASE for the total model is", total_best_mase))
East
Code
## east Prophet ----------------------------------------------------------------east_forecast2 <- east_best_forecast %>%filter(ds >=as.POSIXct("2022-11-29"))performance_east <-full_join(east_test, east_forecast2, by =join_by(ds == ds)) %>%select(ds, y, yhat) %>%mutate(yhat =case_when((yhat <0) ~0,.default = yhat))east_best_proph_test <- performance_east %>%ggplot() +geom_line(aes(x = ds, y = y, color ="dodgerblue"), linewidth =1) +geom_line(aes(x = ds, y = yhat, color ="orange"), linewidth =1) +scale_color_manual(values =c("dodgerblue", "orange"), labels =c("Actual", "Predicted")) +theme_bw() +theme(legend.title =element_blank()) east_best_proph_test
Code
# Check MAE valueeast_best_prophet_mae <-mae(performance_east$y, performance_east$yhat)print(paste("The MAE for the East model is", east_best_prophet_mae))
[1] "The MAE for the East model is 54.5963401771739"
Code
# Check MASE valueeast_best_prophet_mase <-mase(performance_east$y, performance_east$yhat)print(paste("The MASE for the East model is", east_best_prophet_mase))
[1] "The MASE for the East model is 0.616445487611975"
Midwest
Code
## Midwest Prophet ----------------------------------------------------------------midwest_forecast2 <- midwest_best_forecast %>%filter(ds >=as.POSIXct("2022-11-29"))performance_midwest <-full_join(midwest_test, midwest_forecast2, by =join_by(ds == ds)) %>%select(ds, y, yhat) %>%mutate(yhat =case_when((yhat <0) ~0,.default = yhat))midwest_best_proph_test <- performance_midwest %>%ggplot() +geom_line(aes(x = ds, y = y, color ="dodgerblue"), linewidth =1) +geom_line(aes(x = ds, y = yhat, color ="orange"), linewidth =1) +scale_color_manual(values =c("dodgerblue", "orange"), labels =c("Actual", "Predicted")) +theme_bw() +theme(legend.title =element_blank()) midwest_best_proph_test
Code
# Check MAE valuemidwest_best_prophet_mae<-mae(performance_midwest$y, performance_midwest$yhat)print(paste("The MAE for the Midwest model is", midwest_best_prophet_mae))
[1] "The MAE for the Midwest model is 72.5966717493392"
Code
# Check MASE valuemidwest_best_prophet_mase <-mase(performance_midwest$y, performance_midwest$yhat)print(paste("The MASE for the Midwest model is", midwest_best_prophet_mase))
[1] "The MASE for the Midwest model is 0.62736493634715"
South
Code
## South Prophet ----------------------------------------------------------------south_forecast2 <- south_best_forecast %>%filter(ds >=as.POSIXct("2022-11-29"))performance_south <-full_join(south_test, south_forecast2, by =join_by(ds == ds)) %>%select(ds, y, yhat) %>%mutate(yhat =case_when((yhat <0) ~0,.default = yhat))south_best_proph_test <- performance_south %>%ggplot() +geom_line(aes(x = ds, y = y, color ="dodgerblue"), linewidth =1) +geom_line(aes(x = ds, y = yhat, color ="orange"), linewidth =1) +scale_color_manual(values =c("dodgerblue", "orange"), labels =c("Actual", "Predicted")) +theme_bw() +theme(legend.title =element_blank()) south_best_proph_test
Code
# Check MAE valuesouth_best_prophet_mae<-mae(performance_south$y, performance_south$yhat)print(paste("The MAE for the South model is", south_best_prophet_mae))
[1] "The MAE for the South model is 115.016170167609"
Code
# Check MASE valuesouth_best_prophet_mase <-mase(performance_south$y, performance_south$yhat)print(paste("The MASE for the South model is", south_best_prophet_mase))
[1] "The MASE for the South model is 0.595011089545384"
West
Code
## West Prophet ----------------------------------------------------------------west_forecast2 <- west_best_forecast %>%filter(ds >=as.POSIXct("2022-11-29"))performance_west <-full_join(west_test, west_forecast2, by =join_by(ds == ds)) %>%select(ds, y, yhat) %>%mutate(yhat =case_when((yhat <0) ~0,.default = yhat))west_best_proph_test <- performance_west %>%ggplot() +geom_line(aes(x = ds, y = y, color ="dodgerblue"), linewidth =1) +geom_line(aes(x = ds, y = yhat, color ="orange"), linewidth =1) +scale_color_manual(values =c("dodgerblue", "orange"), labels =c("Actual", "Predicted")) +theme_bw() +theme(legend.title =element_blank()) west_best_proph_test
Code
# Check MAE valuewest_best_prophet_mae<-mae(performance_west$y, performance_west$yhat)print(paste("The MAE for the West model is", west_best_prophet_mae))
[1] "The MAE for the West model is 58.4664415871109"
Code
# Check MASE valuewest_best_prophet_mase <-mase(performance_west$y, performance_west$yhat)print(paste("The MASE for the West model is", west_best_prophet_mase))
[1] "The MASE for the West model is 0.65354712625814"